{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def quick_sort(arr, left, right):\n",
    "    # 两指针相遇，结束\n",
    "    if left >= right:\n",
    "        return  # return arr?\n",
    "    base = arr[left]\n",
    "    i, j = left, right\n",
    "    while i < j:\n",
    "        while arr[i] > base and i < j:  # 先从右边开始，base选取最左边\n",
    "            j -= 1\n",
    "        while arr[j] < base and i < j:\n",
    "            i += 1\n",
    "        if i < j:\n",
    "            arr[i], arr[j] = arr[j], arr[i]\n",
    "    # base排序后的位置在i，\n",
    "    arr[left] = arr[i]\n",
    "    arr[i] = base\n",
    "\n",
    "    quick_sort(arr, left, i-1)\n",
    "    quick_sort(arr, i+1, right)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
